home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Web Shop Designer 2000
/
Web Shop Designer 2000 - Disc 1.iso
/
Web Examples
/
AppForms
/
WebSite
/
CGI-BIN
/
CGI6.cgi
< prev
Wrap
Text File
|
1998-08-27
|
8KB
|
230 lines
$cginame = "CGI6";
$cgifolder = "";
$pageURL = "../DoctoralFrameSource.htm";
$cgiurl = "\""."$cgifolder"."$cginame".".cgi"."\"";
$template = "Template1";
###############################################################
# 1.Environmental prefix #
###############################################################
# *-OS platform -* #
$osplat = "Win32";
# *-DB connectivity platform-* #
$dbplat = "ODBC";
###############################################################
# 2.Section of datasource properies #
###############################################################
$dbname = "ADDBOOK";
###############################################################
# 3.Section of columns #
###############################################################
$command = INSERT;
@columns = ( 'FaxNumber','WorkPhone','EmailAddress','Country','StateOrProvince','City','Address','FullName','speciality');
@captions = ( 'Fax Name','Work Phone','Email Address','Country','State or Province','City','Address','Name','speciality');
@columntype = ( 'NONE','NONE','MAIL','NONE','NONE','NONE','NONE','NONE','NONE');
###############################################################
# 4.Section of controls #
###############################################################
@controls = ( 'speciality','name','address','city','state','phone','fax','email');
@controlvalues = ( '','','','','','','','');
&get_control_values(@controls);
###############################################################
# 5.Section of script body where generated SQL #
# statement template is to be placed with appropriate #
# insertions #
###############################################################
@columnvalues = ( $controlvalues[6],$controlvalues[5],$controlvalues[7],"USA",$controlvalues[4],$controlvalues[3],$controlvalues[2],$controlvalues[1],$controlvalues[0]);
$stmt0 = "INSERT INTO Addresses(FaxNumber,WorkPhone,EmailAddress,Country,StateOrProvince,City,Address,FullName,speciality)\n
VALUES ('\$controlvalues[6]','\$controlvalues[5]','\$controlvalues[7]','USA','\$controlvalues[4]','\$controlvalues[3]','\$controlvalues[2]','\$controlvalues[1]','\$controlvalues[0]')";
##################### End of prefix ###########################
#$test = FALSE;
#####################Standard remainder of the script##########
$useplatstr = "use "."$osplat"."::"."$dbplat";
eval $useplatstr;
use CGI ':standard';
$header = "Header";
#################################################################
# 7.Section of script body responsible #
# for input from stdio #
# and output to stdio footer's lines #
#################################################################
print header;
#print "<center><U><B><FONT SIZE=\"+5\">SQL TEST</FONT></B></U><center>";
if (param()) {
}
#################################################################
# 8.Section of script body responsible #
# for placing controls' values #
# in appropriate places in "controlvalues" array #
# and placing received cursor in $cursor variable #
#################################################################
$cursor = param('Cursor');
#################################################################
# 9.Section of script body responsible #
# for placing controls' values #
# in appropriate places in "controlvalues" array #
# and placing received cursor in $cursor variable #
#################################################################
if($test){
print '<FORM ACTION=';
print $cgiurl;
print 'METHOD=POST>';
$colindex = 0;
foreach $control (@controls){
print '<CENTER>';
$temp = $controls[$colindex];
print $temp ;
print '</CENTER><BR>';
print '<CENTER>';
print '<INPUT TYPE="text" NAME="';
print $control;
print '"';
print ' VALUE="';
$temp = $controlvalues[$colindex];
print $temp;
print '" >';
print '</CENTER>';
print '<BR >';
$colindex = $colindex + 1;
}
if($colindex){
print '<BR><BR>';
print '<CENTER>';
print '<INPUT TYPE="Submit" NAME="submit"';
print '</CENTER>';
print '</FORM>';
}
}
#################################################################
# 10.Section of script body where generated SQL #
#statement template is to be placed with appropriate insertions #
# and responsible for getting final sight of SQL #
#################################################################
$stmtval = "\$stmt"."= \""."$stmt0"."\"";
eval $stmtval;
$plat = "\$db"." = "."new "."$osplat"."::"."$dbplat"."("."$dbname".")";
eval $plat;
if (!$db){
&print_db_error;
return;
}
$stmtcount = $stmt;
$_= $stmtcount;
if($command EQ "UPDATE"){
s#^$command#SELECT \* FROM #;
s#SET.*##;
}
if($command EQ "DELETE"){
s#^$command#SELECT \*#;
}
if($command NE "INSERT"){
$stmtcount = $_;
$rowtotal = &get_updated_records;
}
$lor = $db->Sql($stmt);
if ($lor){
&print_sql_error;
return;
}
#################################################################
# 11.Section of script body #
# responsible for output "Query results" line #
# along with total count of rows #
#################################################################
#### only for debugging purpose
if($test){
print "<HR>";
print $stmtval,p;
####
print "<HR>";
}
print "<BR><BR>";
print "<center><U><B>QUERY RESULTS - $command command</B></U><center>";
print "<BR><BR>";
#################################################################
# 14.Section of script body #
# responsible for output of table captions #
# for query columns on feedback page #
#################################################################
if($command NE "DELETE"){
$capindex = 0;
foreach $caption (@captions){
$value = &get_converted_string($columnvalues[$capindex]);
print "<B>$captions[$capindex] = $value</B><BR>";
$capindex = $capindex + 1;
}
}
if($command EQ "UPDATE"){
print "Updated $rowtotal records";
}
if($command EQ "DELETE"){
print "Deleted $rowtotal records";
}
if($pageURL NE ""){
print "<BR><A HREF =\"$pageURL\" TARGET=\"_top\">Go Back</A>";
}
print end_html;
$db->Close();
##################subroutins######
sub get_updated_records
{
local($i)=0;
$db->Sql($stmtcount);
while($db->FetchRow()){
$i = $i+1;
}
local($rowtotal) = $i;
return $i;
}
sub get_control_values
{
local(@controls)=@_;
local($cindex) = 0;
foreach $control (@controls){
if(($t=param($control))){
if($controlvalues[$cindex] EQ 'NO'){
$controlvalues[$cindex] ='YES';
}
if($controlvalues[$cindex] EQ ''){
$t=~ s/'/''/g;
$t=~ s/\|//g;
$controlvalues[$cindex] =$t;
}
}
$cindex = $cindex + 1;
}
}
sub get_converted_string
{
local($name) =@_;
$name=~ s/&/&/g;
$name=~ s/</</g;
$name=~ s/>/>/g;
$name=~ s/⌐/©/g;
$name=~ s/«/®/g;
$name=~ s/"/"/g;
$name=~ s/\n/<BR>/g;
$name=~ s/''/'/g;
return $name;
}
sub print_db_error
{
print "<H1>DATASOURCE OPEN ERROR:</H1>";
print "<P>No such DSN: <u>$dbname</u></P>";
}
sub print_sql_error
{
print "<H1>QUERY EXECUTION ERROR:</H1>";
print "<P>QUERY STATEMENT: <U>$stmt</U></P>";
print "<P>DIAGNOSTICS: <U>";
print $db->Error();
print "</U></P>";
}